package com.example.demo;

import cn.hutool.core.io.IoUtil;
import sun.nio.ch.IOUtil;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

/**
 * @Author: Administrator
 * @Date: 2020/12/24 17:03
 */
public class AppLoader extends ClassLoader{


    @Override
    protected Class<?> findClass(String name) throws ClassNotFoundException {
        return super.findClass(name);
    }

    @Override
    public Class<?> loadClass(String name) throws ClassNotFoundException {
        Class<?> clz = findLoadedClass(name);
        if (clz != null) {
            return clz;
        }
        if(name.startsWith("com.example.demo")){
            try {
                byte[] bs = IoUtil.readBytes(new FileInputStream(new File("C:\\Users\\Administrator\\Downloads\\wukongcrm-72crm-java-master\\demo\\target\\classes\\", name.replaceAll("\\.", "/") + ".class")));
                return defineClass(bs, 0, bs.length);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }
        return getSystemClassLoader().loadClass(name);
    }
}
